<template>
	<view>
		<u-swiper mode="number" indicator-pos="bottomRight" :list="list" :autoplay="false" :current="current"
			@change="change()" :effect3d="true" height="1160"></u-swiper>
		<view class="poster-bottom">
			<view class="poster-bottom-item" @click="saveFile()">
				<u-icon slot="icon" size="88" custom-prefix='gewu' name="baocun"></u-icon>
				<text class="poster-bottom-title">保存到相册</text>
			</view>
			<!-- <view class="poster-bottom-item">
				<u-icon slot="icon" size="88" custom-prefix='gewu' name="weixin"></u-icon>
				<text class="poster-bottom-title">分享给好友</text>
			</view>
			<view class="poster-bottom-item">
				<u-icon slot="icon" size="88" custom-prefix='gewu' name="weixinpengyouquan"></u-icon>
				<text class="poster-bottom-title">分享到朋友圈</text>
			</view> -->
		</view>

		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				current: 0
			}
		},
		onLoad() {
			let that = this;
			that.$u.api.poster({}).then(res => {
				that.list = res.image_url
			})
		},
		methods: {
			change(index) {
				this.current = index
			},
			saveFile() {
				let that = this;
				uni.showLoading({
					title: '正在保存'
				})
				uni.downloadFile({
				    url: that.list[that.current],
				    success: (res) => {
				        if (res.statusCode === 200) {
				            uni.saveImageToPhotosAlbum({
				            	filePath: res.tempFilePath,
				            	success: function(res) {
				            		that.$refs.uToast.show({
				            			title: '保存成功',
				            			type: 'success',
				            		})
									
									uni.hideLoading()
				            	},
				            	fail: function(error) {
				            		that.$refs.uToast.show({
				            			title: '保存失败' + error.errMsg,
				            			type: 'error',
				            		})
									
									uni.hideLoading()
				            	}
				            });
				        }
				    }, fail: function(err){
						uni.hideLoading()
					}
				});
				
				// uni.requestSubscribeMessage({
				// 	tmplIds: ['pU54TKTQvbFU6Vt-YaQTrliA7sWm_8XTUDD0C1dv9rc'],
				// 	success(res) {
				// 		console.log(res)
				// 	}
				// })
				
			}
		}
	}
</script>

<style>
	body {
		background-color: #f5f5f5;
	}

	.poster-bottom {
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		padding: 40rpx;
		position: fixed;
		bottom: 0;
		background-color: rgba(255,255,255, 0.8);
		width: 100%;
		/* padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom); */
	}

	.poster-bottom-item {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.poster-bottom-title {
		margin-top: 20rpx;

	}
</style>
